package com.xiaoyu.merchant.ui.activity;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.widget.TextView;

import com.xiaoyu.commonlib.ui.adapter.ImagePagerAdapter;
import com.xiaoyu.commonlib.ui.base.BaseActivity;
import com.xiaoyu.merchant.MerchantConstants;
import com.xiaoyu.merchant.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 图片查看页面
 */
public class PhotoViewActivity extends BaseActivity {
    @BindView(R.id.activity_photo_view_page)
    ViewPager mViewPager;
    @BindView(R.id.activity_photo_image_num)
    TextView mCountTxt;
    private ImagePagerAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo_view);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        final int pos = getIntent().getIntExtra(MerchantConstants.IMAGER_CLICK_POS,0);
        final List<String> list = (List<String>) getIntent().getSerializableExtra(MerchantConstants.IMAGER_LIST_URL);
        mAdapter = new ImagePagerAdapter(list,this);
        mViewPager.setAdapter(mAdapter);
        mViewPager.setCurrentItem(pos,false);
        mCountTxt.setText(pos+1+"/"+list.size());
        mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                mCountTxt.setText(position+1+"/"+list.size());
            }
        });
    }

    @OnClick(R.id.activity_photo_title_back_btn)
    public void backClick(){
        onBackPressed();
    }
}
